package com.csxh.web.handler.eshop;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.csxh.web.model.eshop.Product;
import com.csxh.web.model.eshop.Subcategory;
import com.csxh.web.service.eshop.ProductService;
import com.csxh.web.service.eshop.SubCategoryService;

@Controller
public class IndexHandler {

	@Autowired
	private SubCategoryService subCategoryService;
	@Autowired
	private ProductService productService;
	
	@RequestMapping("/index")
	public String list(Model model) {
		
		List<Subcategory> bookList = subCategoryService.findCategory(1);
		List<Subcategory> musicList = subCategoryService.findCategory(2);
		List<Subcategory> vidoList = subCategoryService.findCategory(3);
		List<Product> todayHotList = productService.findTodayHotList();
		List<Product> bestSellList = productService.findBestSellList();
		Product newProduct = productService.findNew();
		Product commendProduct = productService.findCommend();
		Product hotDealProduct = productService.findHotDeal();
		
		
		model.addAttribute("bookList",bookList);
		model.addAttribute("musicList",musicList);
		model.addAttribute("vidoList",vidoList);
		model.addAttribute("todayHotList",todayHotList);
		model.addAttribute("bestSellList",bestSellList);

		model.addAttribute("newProduct",newProduct);
		model.addAttribute("commendProduct",commendProduct);
		model.addAttribute("hotDealProduct",hotDealProduct);
		
		
       
		return "index";
	}
}
